package com.android.home.mvp.view.home;

import android.net.Uri;
import android.os.Bundle;
import android.widget.MediaController;
import android.widget.VideoView;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import com.android.home.R;

public class MediaPlayActivity  extends AppCompatActivity {
   @Override
   protected void onCreate(@Nullable Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_media_play);
      VideoView  videoView = (VideoView) findViewById(R.id.main_video);
      MediaController controller = new MediaController(this);//实例化控制器
//        String path = Environment.getExternalStorageDirectory().getAbsolutePath()+"jiaoxue.mp4";
      /**
       * 本地播放
       */
//        videoView.setVideoPath("path");
      /**
       * 网络播放
       */
      videoView.setVideoURI(Uri.parse("/sdcard/h264.mp4"));

      /**
       * 将控制器和播放器进行互相关联
       */
      controller.setMediaPlayer(videoView);
      videoView.setMediaController(controller);
   }
}
